*****************************************************************************************
*****************************************************************************************
*Chapters 1 and 2 of Kropf, Mohr, McGowan, and Pope "A Republic If You Can Afford It"
*8.29.24
*Stata 18.0

**************************************************
****Loading data
cd //Set path

use "General Dataset.dta" 

*Dropping years for analysis
drop if Year < 2008




*****************************
*****************************
*nonresponse analysis in chapter 1
gen costpresent = 0
list Jurisdiction if newcostperreg>1000  & newcostperreg<10000000000
replace costpresent = 1 if newcostperreg >0 & newcostperreg<1000

***1 equals percent cost present
oneway costpresent State, tabulate
//oneway costpresent State, tabulate if newregvoters!=.



*********************PRIMARY focus for chapter 4 > 75% collected for 2008 to 2017
*Must be greater than 80% collected - excluding AK, DE, and ND - which are completely collected


*Not sig  - SD CA WA IA MD NY ND AK NE (also IN FL)  (maybe NC and TN) (others?)
logit costpresent newregvoters if State == "SD"
logit costpresent newregvoters if State == "CA"
logit costpresent newregvoters if State == "WA"
logit costpresent newregvoters if State == "IA"
logit costpresent newregvoters if State == "MD"
logit costpresent newregvoters if State == "NE"
summarize Year if State =="NE" & costpresent==1
*need to set newregvoters to missing not to mess up analysis
drop if CountyFIPS==36047
drop if CountyFIPS==36081
drop if CountyFIPS==36085
drop if CountyFIPS==36005
logit costpresent newregvoters if State == "NY"

summarize Year if State =="SD" & costpresent==1
summarize Year if State =="CA" & costpresent==1
summarize Year if State =="WA" & costpresent==1
summarize Year if State =="IA" & costpresent==1
summarize Year if State =="MD" & costpresent==1

*Sig
logit costpresent newregvoters if State == "NC"
list Jurisdiction if State == "NC" & costpresent == 0
list CountyFIPS if State == "NC" & costpresent == 0
list Year if State == "NC" & costpresent == 0
list newregvoters if State == "NC" & costpresent == 0
list Total_num if State == "NC" & costpresent == 0
logit costpresent newregvoters if State == "NC" & newregvoters >7000
*It does pass the nonresponse test for years prior to 2015 as we used in our previous work
logit costpresent newregvoters if State == "NC" & Year <2015
summarize costpresent if Year <2015 & State =="NC"

summarize costpresent if State =="NC"
logit costpresent newregvoters if State == "TN"
list Jurisdiction if State == "TN" & costpresent == 0
logit costpresent newregvoters if State == "NC" | State =="TN"

summarize Year if State =="TN" & costpresent==1
summarize Year if State =="NC" & costpresent==1

*What about DE and AK? DE only goes to 2014 but AK goes from 2008-2017
drop if CountyFIPS==10001
drop if CountyFIPS==10003
drop if CountyFIPS==10005
summarize Year if State =="AK" & costpresent==1
summarize Year if State =="DE" & costpresent==1

*FOR BOOK
*oneway
oneway costpresent State, tabulate

*********
***Add'l nonresponse for states that maybe didn't completely go from 2008-2016

*Checking for years collected using min and max
*Years for all states >55% collected (5/9 years)
summarize Year if State =="AZ" & costpresent==1
summarize Year if State =="CA" & costpresent==1
summarize Year if State =="CT" & costpresent==1
*DE 2008-2014
summarize Year if State =="DE" & costpresent==1
*FL 2011 - 2016
summarize Year if State =="FL" & costpresent==1
summarize Year if State =="GA" & costpresent==1
summarize Year if State =="IA" & costpresent==1
*IN 2011-2016
summarize Year if State =="IN" & costpresent==1
*KS 2009-2016
summarize Year if State =="KS" & costpresent==1
summarize Year if State =="LA" & costpresent==1
summarize Year if State =="MD" & costpresent==1
summarize Year if State =="MN" & costpresent==1
summarize Year if State =="NC" & costpresent==1
summarize Year if State =="ND" & costpresent==1
summarize Year if State =="NE" & costpresent==1
summarize Year if State =="NJ" & costpresent==1
summarize Year if State =="NY" & costpresent==1
summarize Year if State =="OK" & costpresent==1
summarize Year if State =="RI" & costpresent==1
summarize Year if State =="SC" & costpresent==1
summarize Year if State =="SD" & costpresent==1
summarize Year if State =="TN" & costpresent==1
*UT 2010 -2016
summarize Year if State =="UT" & costpresent==1
summarize Year if State =="WA" & costpresent==1
summarize Year if State =="WY" & costpresent==1


*for any that do not go all the way to 
summarize costpresent if Year <2015 & State =="DE"
summarize costpresent if Year >2010 & State =="FL"
summarize costpresent if Year >2010 & State =="IN"
summarize costpresent if Year >2008 & State =="KS"
*Only UT did not get above 75%
summarize costpresent if Year >2009 & State =="UT"

*Others greater than 75% collected for select years
*DE is completely collected for 2008-2014
*IN is not sig -> consider for inclusion 2011- 2016
logit costpresent newregvoters if State == "IN"
summarize Year if State =="IN" & costpresent==1
*KS is sig
logit costpresent newregvoters if State == "KS"
*FL is 57% --> consider for inclusion 2011- 2016
logit costpresent newregvoters if State == "FL"


*Others NOT IN ANALYSIS
*65 - 70% collected
*Arizona Georgia Lousiana
logit costpresent newregvoters if State == "GA"
*Georgia is sig
logit costpresent newregvoters if State == "AZ"
*AZ is not sig
summarize Year if State =="AZ" & costpresent==1
logit costpresent newregvoters if State == "LA"
summarize Year if State =="LA" & costpresent==1
*LA is  sig

*55% - 65%
*NJ is 64.8% - not sig***************************for all years
logit costpresent newregvoters if State == "NJ"
summarize Year if State =="NJ" & costpresent==1

summarize Year if State =="FL" & costpresent==1
*UT - not sig BUT only 2010 to 2016
logit costpresent newregvoters if State == "UT"
summarize Year if State =="UT" & costpresent==1


*******************************
*******************************
***Ch 2
* Maps come from PowerBI - see export above

*Across states
oneway realcostperbal State1, tabulate
oneway realcostperreg State1, tabulate

***Comparison of costs over time (Average 2008-2016 change)
**Expenditure per registered voters
*Nominal
oneway newcostperreg Year, tabulate
di (10.365-9.001)/9.001*100
//15.15
*Real
oneway realcostperreg Year, tabulate
*percentage change from 2008 to 2016 (Amt2016-Amt2008/Amt2008)
di (11.121-10.798)/10.798*100
//2.99%

**
*figures over time

//ssc install lgraph
lgraph realcostperreg Year if Year<2017
oneway realcostperreg Year, tabulate

lgraph realcostperbal Year if Year<2017
oneway realcostperbal Year, tabulate

*figures disaggregated by region
recode StateFIPS (17 18 19 20 26 27 29 31 38 39 46 55=1 "Midwest") (1 5 12 13 21 22 28 37 40 45 47 48=2 "South") (9 10 23 24 25 33 34 36 42 44 50 51 54=3 "NE & Mid-Atlantic") (2 4 6 8 15 16 30 32 35 41 49 53 56=4 "West")  (.=.), gen (region)

lgraph realcostperreg Year region if Year<2017

*Midwest
oneway realcostperreg Year if region==1, tabulate
di (10.737-9.978)/9.978*100
*7.61%

**South
oneway realcostperreg Year if region==2, tabulate
di (11.000-9.106)/9.106*100
*20.80%

*Northeast and midatlantic
oneway realcostperreg Year if region==3, tabulate
di (11.541-12.149)/12.149*100
*-5.00%

**West
oneway realcostperreg Year if region==4, tabulate
di (11.772-17.151)/17.151*100

